#include "QueryFramework.h"
#include "Config.h"
#include <stdlib.h>

SelectObject QueryFramework_Select(int eID)
{
	int i=0;
	SelectObject so;
	PersistentFramework_Load();
	for(i=0;i<pObject.count;i++)
	{
		if(eID == pObject.employeeInfoArray[i].id && pObject.employeeInfoArray[i].isDeleted == FALSE)
		{
			so.count = 1;
			so.isNull = FALSE;
			so.resultArray[0] = pObject.employeeInfoArray[i];
			return so;
		}
	}
	so.count = 0;
	so.isNull = TRUE;
	return so;
}
SelectObject QueryFramework_SelectAll()
{
	int i;
	SelectObject so;
	int j= 0;
	PersistentFramework_Load();
	for(i=0;i<pObject.count;i++)
	{
		if(pObject.employeeInfoArray[i].isDeleted == FALSE)
		{
			so.resultArray[j] = pObject.employeeInfoArray[i];
			j++;
		}
	}
	if(0==j)
	{
		so.isNull = TRUE;
	}
	else
	{
		so.isNull = FALSE;
	}
	so.count = j;
	return so;
}
int QueryFramework_Insert(EmployeeInfo eInfo)
{
	PersistentFramework_Load();
	pObject.employeeInfoArray[pObject.count] = eInfo;
	pObject.employeeInfoArray[pObject.count].id = pObject.count;
	pObject.count++;
	PersistentFramework_Save();
	return TRUE;
}
int QueryFramework_Update(int eID, EmployeeInfo eInfo)
{
	int i;
	int opFlag = FALSE;
	PersistentFramework_Load();
	for(i=0;i<pObject.count;i++)
	{
		if(eID == pObject.employeeInfoArray[i].id)
		{
			pObject.employeeInfoArray[i] = eInfo;
			pObject.employeeInfoArray[i].id = eID;
			opFlag = TRUE;
		}
	}
	PersistentFramework_Save();
	return opFlag;
}
int QueryFramework_Delete(int eID)
{
	int i;
	int opFlag = FALSE;
	PersistentFramework_Load();
	for(i=0;i<pObject.count;i++)
	{
		if(eID == pObject.employeeInfoArray[i].id)
		{
			pObject.employeeInfoArray[i].isDeleted = 1;
			opFlag = TRUE;
		}
	}
	PersistentFramework_Save();
	return opFlag;
}